package com.bwie.system.controller;

import com.bwie.common.doamin.dto.LoginDTO;
import com.bwie.common.doamin.dto.RegisterDTO;
import com.bwie.common.doamin.model.SysUser;
import com.bwie.common.doamin.vo.LoginVO;
import com.bwie.common.result.Result;
import com.bwie.system.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户控制层
 *
 * @author <a href="mailto:2943147140@qq.com">刘洋朔</a>
 * @version 1.0
 * @description: 用户控制层
 * @date 2025/9/9 10:49
 */
@RestController
@RequestMapping("system")
public class SystemController {
    /**
     * 用户业务层
     */
    @Autowired
    private SysUserService sysUserService;

    /**
     * 获取登录的用户信息
     * @param loginDTO
     * @return
     */
    @PostMapping("selLoginInfo")
    public Result<SysUser> selLoginInfo(@RequestBody LoginDTO loginDTO){
        SysUser sysUser = sysUserService.selLoginInfo(loginDTO);
        return Result.success(sysUser);
    }

    /**
     * 获取登录的角色id
     * @param userId
     * @return
     */
    @GetMapping("selRoleByUserId/{userId}")
    public Result<Long> selRoleByUserId(@PathVariable("userId") Long userId){
        Long roleId = sysUserService.selRoleByUserId(userId);
        return Result.success(roleId);
    }

    /**
     * 用户注册
     * @param registerDTO
     * @return void
     */
    @PostMapping("register")
    public Result<Void> register(@RequestBody @Valid RegisterDTO registerDTO){
        sysUserService.register(registerDTO);
        return Result.success();
    }
}
